package mess;

public class LeeCode_50 {
    public static void main(String[] args) {
        System.out.println(myPow(2, 0));
    }
    private static double myPow(double x, int n) {
        //折半算法
        double result = 1.0;
        //4 2 1
        //3 1
        //6 3 1
        for (int i = n; i != 0; i /= 2) {
            if (i % 2 != 0)
                result *= x;
            x *= x;
        }
        return n < 0 ? 1 / result : result;
       /* double result = x;
        if (x == 0)
            return 0;
        if (x == 1)
            return 1;
        if (n == 0)
            return 1;
        if (n > 0){
            for (int i = 0; i < n - 1; i++)
                result *= x;
        }
        if (n < 0){
            for (int i = 0; i < -n - 1; i++)
                result *= x;
            result = 1 / result;
        }
        return result;*/
    }
}
